package com.webapp.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.webapp.model.Employee;
import com.webapp.model.ManagerModel;

/**
 * Servlet implementation class DeletePost
 */
public class EditEmployee extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EditEmployee() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		int employeeSSN = Integer.parseInt(request.getParameter("EditEmployee"));
		ManagerModel mm = new ManagerModel();
		Employee em = mm.getEmployee(employeeSSN);
		if(em == null) {
			response.sendRedirect("ManageEmployees.jsp?employee=notexists");
		} else {
			System.out.println(em.getSSN());
			session.setAttribute("Employee", mm.getEmployee(employeeSSN));
			response.sendRedirect("CreateEmployee.jsp?employee=edit");
		}
	}
}
